//
//  SDSubCell.m
//  SDNestedTablesExample
//
//  Created by Daniele De Matteis on 21/05/2012.
//  Copyright (c) 2012 Daniele De Matteis. All rights reserved.
//

#import "SDSubCell2.h"
#import "clsOtherFun.h"
#import "clsAntsService.h"
#import "NewSendViewController.h"
#import "UIAlertView+Blocks.h"
@implementation SDSubCell2

@synthesize parentTable;
@synthesize cellIndex;
-(void)awakeFromNib
{
    self.contentView.backgroundColor = [UIColor clearColor];
    self.delect.layer.borderColor = [UIColor blackColor].CGColor;
    self.change.layer.borderColor = [UIColor blackColor].CGColor;
    self.change.layer.borderWidth = 1;
    self.delect.layer.borderWidth = 1;
}

-(void)fillData:(NSDictionary *)data
{
    self.MemberName.text = [data objectForKey:@"MemberName"];
    self.MemberTelephone.text = [data objectForKey:@"MemberTelephone"];
    NSString *privince = [data objectForKey:@"ProvinceName"];
    NSString *City = [data objectForKey:@"CityName"];
    NSString *District = [data objectForKey:@"DistrictName"];
    NSString *st = privince;
    if (![privince isEqualToString:City]) {
        st = [NSString stringWithFormat:@"%@%@",st,City];
    }
    if (![City isEqualToString:District]) {
        st = [NSString stringWithFormat:@"%@%@",st,District];
    }
    st = [NSString stringWithFormat:@"%@%@",st,[data objectForKey:@"SEAdress"]];
    
   
    self.SEName.text = [data objectForKey:@"SEName"];
    self.SETelephone.text = [data objectForKey:@"SETelephone"];
    NSString *mprivince = [data objectForKey:@"MProvinceName"];
    NSString *mCity = [data objectForKey:@"MCityName"];
    NSString *mDistrict = [data objectForKey:@"MDistrictName"];
    NSString *mst = mprivince;
    if (![mprivince isEqualToString:mCity]) {
        mst = [NSString stringWithFormat:@"%@%@",mst,mCity];
    }
    if (![mCity isEqualToString:mDistrict]) {
        mst = [NSString stringWithFormat:@"%@%@",mst,mDistrict];
    }
    mst = [NSString stringWithFormat:@"%@%@",mst,[data objectForKey:@"MemberAdress"]];
    self.SEAdress.text = st;
    self.MemberAdress.text = mst;
    self.GoodsName.text = [data objectForKey:@"GoodsName"];
    NSString *str =[data objectForKey:@"GoodsWeight"];
    if (![str isEqual:[NSNull null]]) {
         self.GoodsWeight.text = [NSString stringWithFormat:@"%.1f",[str floatValue]];
    }
    str =[data objectForKey:@"GoodsSumMoney"];
    if (![str isEqual:[NSNull null]]) {
    self.GoodsSumMoney.text = [NSString stringWithFormat:@"%.1f",[str floatValue]];
    }
    str =[data objectForKey:@"GoodsDSMoney"];
     if (![str isEqual:[NSNull null]]) {
    self.GoodsDSMoney.text = [NSString stringWithFormat:@"%.1f",[str floatValue]];
     }
    str =[data objectForKey:@"GoodsFreight"];
     if (![str isEqual:[NSNull null]]) {
    self.GoodsFreight.text = [NSString stringWithFormat:@"%.1f",[str floatValue]];
     }
    str =[data objectForKey:@"GoodsPack"];
     if (![str isEqual:[NSNull null]]) {
    self.GoodsPack.text = [NSString stringWithFormat:@"%.1f",[str floatValue]];
     }
    str =[data objectForKey:@"GoodsBox"];
     if (![str isEqual:[NSNull null]]) {
    self.GoodsBox.text = [NSString stringWithFormat:@"%.1f",[str floatValue]];
     }
    self.IsBJ.text = [[data objectForKey:@"IsBJ"]integerValue]==1?@"是":@"否";
    self.dic = data;
    
}
- (IBAction)DeleteAction:(id)sender {
    RIButtonItem *cancel = [RIButtonItem itemWithLabel:@"取消" action:^{
        
    }];
    RIButtonItem *sure = [RIButtonItem itemWithLabel:@"確定" action:^{
        if ([clsOtherFun CheckNetworkStatus:YES]) {
            clsAntsService *ants = [[clsAntsService alloc]init];
            [ants DeleteSendExpress:[self.dic objectForKey:@"SendExpressMember"] action:^(NSDictionary *dic) {
                NSString *status = [dic objectForKey:@"status"];
                if ([status integerValue]==200) {
                    [[NSNotificationCenter defaultCenter]postNotificationName:@"DeleteSuccess" object:self.dic];
                }
                [clsOtherFun ShowMsg:[dic objectForKey:@"message"]];
                
            }];
        }else{
            [clsOtherFun ShowNoNetworkMsg];
        }
    }];
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"是否刪除此條數據？" cancelButtonItem:cancel otherButtonItems:sure, nil];
    [alert show];
    
}
- (IBAction)ChangeAcyion:(id)sender {
    if ([[self.dic objectForKey:@"ExpressID"]isKindOfClass:[NSNull class]]) {
        NewSendViewController *new = [[NewSendViewController alloc]initWithNibName:@"NewSendViewController" bundle:nil];
        new.isBack=YES;
        new.dic =self.dic;
        [self.parentViewController.navigationController pushViewController:new animated:YES];
    }else{
        [clsOtherFun ShowMsg:@"已發貨，不能修改"];
    }
}
@end
